package com.danielagarza.app;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;

public class Home extends FragmentActivity {

	private SectionsPagerAdapter mSectionsPagerAdapter;
	private ViewPager mViewPager;
	
	Facebook facebook = new Facebook("462535810477183");

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		mSectionsPagerAdapter = new SectionsPagerAdapter(
				getSupportFragmentManager());
		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);
		
        /*facebook.authorize(this, new DialogListener() {
            
        	@Override
            public void onComplete(Bundle values) {
            	Log.i("SSO Test", "JSON de Respuesta: " + values);
            }

            @Override
            public void onFacebookError(FacebookError error) {
            	Log.i("SSO Test", "A facebook error have been ocurred...");
            	Log.i("SSO Test", error.toString());
            }

            @Override
            public void onError(DialogError e) {
            	Log.i("SSO Test", "A dialog error have been ocurred...");
            	Log.i("SSO Test", e.toString());
            }

            @Override
            public void onCancel() {
            	Log.i("SSO Test", "Action Canceled...");
            }
        });
		*/
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_home, menu);
		return true;
	}


	public class SectionsPagerAdapter extends FragmentPagerAdapter {

		public SectionsPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			
			switch (position) {
			case 0:
				//ProgressDialog pd = ProgressDialog.show(this.getActivity(),"Twitter","Mensaje",true, false);
				Noticias noticiasFragment = new Noticias();
				return  noticiasFragment;
			case 1:
				Twitter twitterFragment = new Twitter();
				return twitterFragment;
			case 2:
				Agenda agendaFragment = new Agenda();
				return agendaFragment;
			}
			

			return null;
		}

		@Override
		public int getCount() {
			return 3;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			switch (position) {
			case 0:
				return getString(R.string.title_noticias);
			case 1:
				return getString(R.string.title_twitter);
			case 2:
				return getString(R.string.title_agenda);
			}
			return null;
		}
		
		

	}
	
	
	 @Override
	    public void onActivityResult(int requestCode, int resultCode, Intent data) {
	        super.onActivityResult(requestCode, resultCode, data);
	        facebook.authorizeCallback(requestCode, resultCode, data);
	    }

}
